package btp.CoordinateSystems;

import btp.Time.SiderealTime;
import btp.Trigonometry.Angle;

public class HorizontalCoordinate {
	double azimuth;
	double altitude;
	Latitude latitude;
	SiderealTime time;
	
	public HorizontalCoordinate(double azimuth, double altitude, Latitude latitude, SiderealTime time) {
		this.azimuth = azimuth;
		this.altitude = altitude;
		this.latitude = latitude;
		this.time=time;
	}

	public  double getAzimuth() {
		return azimuth;
	}

	public void setAzimuth(double azimuth) {
		this.azimuth = azimuth;
	}

	public  double getAltitude() {
		return altitude;
	}

	public  void setAltitude(double altitude) {
		this.altitude = altitude;
	}

	public Latitude getLatitude() {
		return latitude;
	}

	public void setLatitude(Latitude latitude) {
		//calculate azimuth and altitude here.
		this.latitude = latitude;
	}
	
	
	public static HorizontalCoordinate getHorizontalFromEquatorial(EquatorialCoordinate e, SiderealTime time, Latitude latitude){
		double h = e.rightAscensionToHourAngle(time).toDouble()*2*Math.PI;
		System.out.println(h);
		double sinh = Math.sin(h);
		double cosh = Math.cos(h);
		double sindelta = Math.sin(Angle.fromDouble(e.declination).toRadians());
		double cosdelta = Math.cos(Angle.fromDouble(e.declination).toRadians());
		double sinphi = Math.sin(Angle.fromDouble(latitude.toDouble()).toRadians());
		double cosphi = Math.cos(Angle.fromDouble(latitude.toDouble()).toRadians());
		double azimuth = Math.atan(sinh/(cosh*sinphi-sindelta*cosphi/cosdelta))*180/Math.PI;
		double altitude = Math.asin(sinphi*sindelta+cosphi*cosdelta*cosh)*180/Math.PI;
		return new HorizontalCoordinate(azimuth, altitude, latitude, time);
	}
	
	
}
